<?php
	class NavAction extends BaseAction{
		public function index(){
			if(!$this->isPost()){
				$this->display();
			}else{
				$data['nav_name'] = $_POST['nav_name'];
				$data['nav_sate'] = $_POST['nav_sate'];
				$data['locations'] = $_POST['locations'];
				
				$result = M("nav")->data($data)->add();
				echo M("nav")->getlastsql();exit;
				if($result){
					$this->assign("jumpUrl","__URL__/index");
					$this->assign("waitSecond",3);
					$this->success("导航添加成功！！！");

				}else{
					$this->assign("jumpUrl","__URL__/index");
					$this->assign("waitSecond",3);
					$this->error("导航添加失败！！！");
				}
			}
		}

		public function navupdate(){
			if(!$this->isPost()){
				$result = M("nav")->order("nav_sate desc")->select();
				$this->assign("nav",$result);
				$this->display();
			}else{
				if($_POST['fun']=='u'){
					$nav_id = $_POST['nav_id'];
					$result = M("nav")->where("nav_id=$nav_id")->select();
					$this->assign("nav",$result);
					$this->display("update");
				}elseif($_POST['fun']=="upd"){
					$nav_id = $_POST['nav_id'];
					$data['nav_name'] = $_POST['nav_name'];
					$data['nav_sate'] = $_POST['nav_sate'];
					$data['locations'] = $_POST['locations'];
					$result = M("nav")->where("nav_id = $nav_id")->save($data);
					if($result){
						$this->assign("jumpUrl","__URL__/navupdate");
						$this->assign("waitSecond",3);
						$this->success("导航修改成功！！！");

					}else{
						$this->assign("jumpUrl","__URL__/navupdate");
						$this->assign("waitSecond",3);
						$this->error("导航修改失败！！！");
					}
				}elseif($_POST['fun']=='del'){
					$nav_id = $_POST['nav_id'];
					$result = M("nav")->where("nav_id=$nav_id")->delete();
					if($result){
						echo 1;
					}else{
						echo 2;
					}
				}
			}
		}

		public function friendurl(){
			if(!$this->isPost()){
				$this->display();
			}else{
				$data['f_name'] = $_POST['f_name'];
				$data['f_url'] = $_POST['f_url'];
				$data['f_sate'] = $_POST['f_sate'];
				$result = M("friendurl")->data($data)->add();
				if($result){
					$this->assign("jumpUrl","__URL__/friendurl");
					$this->assign("waitSecond",3);
					$this->success("友情链接添加成功！！！");

				}else{
					$this->assign("jumpUrl","__URL__/friendurl");
					$this->assign("waitSecond",3);
					$this->error("友情链接添加失败！！！");
				}
			
			}
		}
		public function flists()
		{
			if(!$this->isPost())
			{
				$result = M("friendurl")->select();
				$this->assign("furl",$result);
				$this->display();
			}
			else
			{
				if($_POST['fun']=='u'){
					$f_id = $_POST['f_id'];
					$result = M("friendurl")->where("f_id=$f_id")->select();

					$this->assign("furl",$result);
					$this->display("fupdate");
				}elseif($_POST['fun']=="upd"){
					$f_id = $_POST['f_id'];
					$data['f_name'] = $_POST['f_name'];
					$data['f_sate'] = $_POST['f_sate'];
					$data['f_url'] = $_POST['f_url'];
					$result = M("friendurl")->where("f_id=$f_id")->save($data);
					if($result){
						$this->assign("jumpUrl","__URL__/flists");
						$this->assign("waitSecond",3);
						$this->success("友情链接修改成功！！！");

					}else{
						$this->assign("jumpUrl","__URL__/flists");
						$this->assign("waitSecond",3);
						$this->error("友情链接修改失败！！！");
					}
				}elseif($_POST['fun']=='del'){
					$f_id = $_POST['f_id'];
					$result = M("friendurl")->where("f_id=$f_id")->delete();
					if($result){
						echo 1;
					}else{
						echo 2;
					}
				}
			}
		}
		
		/**
		 * @name footlink
		 * @desc 底部链接列表
		 */
		public function footlink()
		{
			$result = M("footinfo")->select();
			$this->assign("footinfo",$result);
			$this->display();
		}
		
		
		/**
		 * @name editfootlink
		 * @desc 编辑底部链接地址
		 */
		public function editfootlink()
		{
			if(!$this->isPost())
			{
				$f_id = intval($_GET['f_id']);
				if($f_id){
					$result = M("footinfo")->where("id=$f_id")->select();
					$this->assign("footinfo",$result);
					$this->display("footupdate");
				}
			}
			else
			{
				$f_id 				= $_POST['f_id'];
				$data['content'] 	= $_POST['contents'];
				$result = M("footinfo")->where("id=$f_id")->save($data);
				if($result)
				{
					$this->assign("jumpUrl","__URL__/footlink");
					$this->assign("waitSecond",3);
					$this->success("修改成功！！！");

				}else{
					$this->assign("jumpUrl","__URL__/footlink");
					$this->assign("waitSecond",3);
					$this->error("修改失败！！！");
				}
			}			
		}
	
}
?>